$(function(){
	var url = common.url();
	var began = 0;
	var listlen = 10;
	
	//关于点击后的连接问题，以及内容
	var jk = '/api/attachment/attachmentList.json';
	var loginurl= common.Interface('onlogin')[0]
	$.ajax({
		url : loginurl,
		type: "POST",
		error: function(request) {
			//console.log(request)
		},
		dataType:"json",
		success: function(data) {
			if(data.ret){
				if(data.data == 'UpFile'){
					common.hash('page',fnhash);
				}else{
					//$('.cont').remove()
					$('.youcede').remove();
					$('.header-box').css({'display':'block'});
					$('.boxbg').css({'display':'block'});
					$('.tanbox').css({'display':'none'});
					$('.login-box').css({'display':'block'});
					$('.showboxtitle').html('登陆');
					$('.baocuo').html('此页面需要上传资料专用账户可以访问...');
					
				}
			}
		}
	})
	
	function fnhash(hash){
		//分页
		if(common.hashlist().page){
			began = (common.hashlist().page-1)*listlen
		}
		var url = jk +'?offset='+ began +'&limit='+ listlen
		$.ajax({
				url : url,
				type: "POST",
				error: function(request) {
					console.log(request)
				},
				dataType:"json",
				success: function(data) {
					if(data.rows.length>0){
						var json = data;
						var pages =Math.ceil(json.total / listlen);
						common.pagesgn(pages,6);
						$('.upfilebox').html('')
						for(var i=0;i<json.rows.length;i++){
							var title = common.maxlen(json.rows[i].name,40,true);
							var html = '<li class="clear">\
								<p class="xmname">'+ title +'</p>\
								<p class="xmstatus">'+ json.rows[i].att_creat_time +'</p>\
								<div class="caozuo clear">\
								<a href="'+ json.rows[i].attachment_url +'" class="download ">下载</a></div></li>';
							$('.upfilebox').append(html)
						}
					}else{
						$('.pages').css({'display':'none'});
					}
				}
			})
	}
})
